import {
  getBackProductDetail,
} from '../../services/order/api';


export default {
  namespace: 'refundOrderDetail',

  state: {

    loading: true,

    routePararm: {
      id: '',
    }

  },

  // 路由传参方法A_
  // subscriptions: {
  //   /**
  //    * 监听浏览器地址，当跳转到 /orderManagement/refundOrderDetail 时进入该方法
  //    * @param dispatch 触发器，用于触发 effects 中的 query 方法
  //    * @param history 浏览器历史记录，主要用到它的 location 属性以获取地址栏地址
  //    */
  //   setup ({ dispatch, history }) {
  //     history.listen((location) => {
  //       if (location.pathname === '/orderManagement/refundOrderDetail') {
  //         console.log('location is: %o', location);
  //         console.log('重定向接收参数：%o', location.state)
  //         // 调用 effects 属性中的 query 方法，并将 location.state 作为参数传递
  //         dispatch({
  //           type: 'query',
  //           payload: location.state,
  //         })
  //       }
  //     });
  //   },
  // },

  effects: {

    *fetchGetBackProductDetail({payload, callback}, { call, put }) {
      const response = yield call(getBackProductDetail, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {refundOrderDetailData: response.data},
        });
        if (callback) callback();
      }
    },

    // 路由传参方法_B
    // *query ({ payload }, { call, put }) {
    //   console.log('payload is: %o', payload);
    //   yield put({
    //     type: 'save',
    //     payload: {routePararm: payload},
    //   });
    // }
    
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
